/**
 * SMOF js
 *
 * contains the core functionalities to be used
 * inside SMOF
 */

jQuery.noConflict();

/** Fire up jQuery - let's dance! 
 */
jQuery(document).ready(function($){
	
	//(un)fold options in a checkbox-group
  	jQuery('.fld').click(function() {
    	var $fold='.f_'+this.id;
    	$($fold).slideToggle('normal', "swing");
  	});
	
	//delays until AjaxUpload is finished loading
	//fixes bug in Safari and Mac Chrome
	if (typeof AjaxUpload != 'function') { 
			return ++counter < 6 && window.setTimeout(init, counter * 500);
	}
	
	//hides warning if js is enabled			
	$('#js-warning').hide();
	
	//Tabify Options			
	$('.group').hide();
	
	// Display last current tab	
	if ($.cookie("of_current_opt") === null) {
		$('.group:first').fadeIn('fast');	
		$('#of-nav li:first').addClass('current');
	} else {
	
		var hooks = $('#hooks').html();
		hooks = jQuery.parseJSON(hooks);
		
		$.each(hooks, function(key, value) { 
		
			if ($.cookie("of_current_opt") == '#of-option-'+ value) {
				$('.group#of-option-' + value).fadeIn();
				$('#of-nav li.' + value).addClass('current');
			}
			
		});
	
	}
				
	//Current Menu Class
	$('#of-nav li a').click(function(evt){
	// event.preventDefault();
				
		$('#of-nav li').removeClass('current');
		$(this).parent().addClass('current');
							
		var clicked_group = $(this).attr('href');
		
		$.cookie('of_current_opt', clicked_group, { expires: 7, path: '/' });
			
		$('.group').hide();
							
		$(clicked_group).fadeIn('fast');
		return false;
						
	});

	//Expand Options 
	var flip = 0;
				
	$('#expand_options').click(function(){
		if(flip == 0){
			flip = 1;
			$('#of_container #of-nav').hide();
			$('#of_container #content').width(760);
			$('#of_container .group').add('#of_container .group h2').show();
	
			$(this).removeClass('expand');
			$(this).addClass('close');
			$(this).text('Close');
					
		} else {
			flip = 0;
			$('#of_container #of-nav').show();
			$('#of_container #content').width(600);
			$('#of_container .group').add('#of_container .group h2').hide();
			$('#of_container .group:first').show();
			$('#of_container #of-nav li').removeClass('current');
			$('#of_container #of-nav li:first').addClass('current');
					
			$(this).removeClass('close');
			$(this).addClass('expand');
			$(this).text('Expand');
				
		}
			
	});
	
	//Update Message popup
	$.fn.center = function () {
		this.animate({"top":( $(window).height() - this.height() - 200 ) / 2+$(window).scrollTop() + "px"},100);
		this.css("left", 250 );
		return this;
	}
		
			
	$('#of-popup-save').center();
	$('#of-popup-reset').center();
	$('#of-popup-fail').center();
			
	$(window).scroll(function() { 
		$('#of-popup-save').center();
		$('#of-popup-reset').center();
		$('#of-popup-fail').center();
	});
			

	//Masked Inputs (images as radio buttons)
	$('.of-radio-img-img').click(function(){
		$(this).parent().parent().find('.of-radio-img-img').removeClass('of-radio-img-selected');
		$(this).addClass('of-radio-img-selected');
	});
	$('.of-radio-img-label').hide();
	$('.of-radio-img-img').show();
	$('.of-radio-img-radio').hide();
	
	//Masked Inputs (background images as radio buttons)
	$('.of-radio-tile-img').click(function(){
		$(this).parent().parent().find('.of-radio-tile-img').removeClass('of-radio-tile-selected');
		$(this).addClass('of-radio-tile-selected');
	});
	$('.of-radio-tile-label').hide();
	$('.of-radio-tile-img').show();
	$('.of-radio-tile-radio').hide();

	//AJAX Upload
	function of_image_upload() {
	$('.image_upload_button').each(function(){
			
	var clickedObject = $(this);
	var clickedID = $(this).attr('id');	
			
	var nonce = $('#security').val();
			
	new AjaxUpload(clickedID, {
		action: ajaxurl,
		name: clickedID, // File upload name
		data: { // Additional data to send
			action: 'of_ajax_post_action',
			type: 'upload',
			security: nonce,
			data: clickedID },
		autoSubmit: true, // Submit file after selection
		responseType: false,
		onChange: function(file, extension){},
		onSubmit: function(file, extension){
			clickedObject.text('Uploading'); // change button text, when user selects file	
			this.disable(); // If you want to allow uploading only 1 file at time, you can disable upload button
			interval = window.setInterval(function(){
				var text = clickedObject.text();
				if (text.length < 13){	clickedObject.text(text + '.'); }
				else { clickedObject.text('Uploading'); } 
				}, 200);
		},
		onComplete: function(file, response) {
			window.clearInterval(interval);
			clickedObject.text('Upload Image');	
			this.enable(); // enable upload button
				
	
			// If nonce fails
			if(response==-1){
				var fail_popup = $('#of-popup-fail');
				fail_popup.fadeIn();
				window.setTimeout(function(){
				fail_popup.fadeOut();                        
				}, 2000);
			}				
					
			// If there was an error
			else if(response.search('Upload Error') > -1){
				var buildReturn = '<span class="upload-error">' + response + '</span>';
				$(".upload-error").remove();
				clickedObject.parent().after(buildReturn);
				
				}
			else{
				var buildReturn = '<img class="hide of-option-image" id="image_'+clickedID+'" src="'+response+'" alt="" />';

				$(".upload-error").remove();
				$("#image_" + clickedID).remove();	
				clickedObject.parent().after(buildReturn);
				$('img#image_'+clickedID).fadeIn();
				clickedObject.next('span').fadeIn();
				clickedObject.parent().prev('input').val(response);
			}
		}
	});
			
	});
	
	}
	
	of_image_upload();
			
	//AJAX Remove Image (clear option value)
	$('.image_reset_button').live('click', function(){
	
		var clickedObject = $(this);
		var clickedID = $(this).attr('id');
		var theID = $(this).attr('title');	
				
		var nonce = $('#security').val();
	
		var data = {
			action: 'of_ajax_post_action',
			type: 'image_reset',
			security: nonce,
			data: theID
		};
					
		$.post(ajaxurl, data, function(response) {
						
			//check nonce
			if(response==-1){ //failed
							
				var fail_popup = $('#of-popup-fail');
				fail_popup.fadeIn();
				window.setTimeout(function(){
					fail_popup.fadeOut();                        
				}, 2000);
			}
						
			else {
						
				var image_to_remove = $('#image_' + theID);
				var button_to_hide = $('#reset_' + theID);
				image_to_remove.fadeOut(500,function(){ $(this).remove(); });
				button_to_hide.fadeOut();
				clickedObject.parent().prev('input').val('');
			}
						
						
		});
					
	}); 

	// Style Select
	(function ($) {
	styleSelect = {
		init: function () {
		$('.select_wrapper').each(function () {
			$(this).prepend('<span>' + $(this).find('.select option:selected').text() + '</span>');
		});
		$('.select').live('change', function () {
			$(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>');
		});
		$('.select').bind($.browser.msie ? 'click' : 'change', function(event) {
			$(this).prev('span').replaceWith('<span>' + $(this).find('option:selected').text() + '</span>');
		}); 
		}
	};
	$(document).ready(function () {
		styleSelect.init()
	})
	})(jQuery);
	
	
	/** Aquagraphite Slider MOD */
	
	//Hide (Collapse) the toggle containers on load
	$(".slide_body").hide(); 

	//Switch the "Open" and "Close" state per click then slide up/down (depending on open/close state)
	$(".slide_edit_button").live( 'click', function(){
		$(this).parent().toggleClass("active").next().slideToggle("fast");
		return false; //Prevent the browser jump to the link anchor
	});	
	
	// Update slide title upon typing		
	function update_slider_title(e) {
		var element = e;
		if ( this.timer ) {
			clearTimeout( element.timer );
		}
		this.timer = setTimeout( function() {
			$(element).parent().prev().find('strong').text( element.value );
		}, 100);
		return true;
	}
	
	$('.of-slider-title').live('keyup', function(){
		update_slider_title(this);
	});
		
	
	//Remove individual slide
	$('.slide_delete_button').live('click', function(){
	// event.preventDefault();
	var agree = confirm("Are you sure you wish to delete this slide?");
		if (agree) {
			var $trash = $(this).parents('li');
			//$trash.slideUp('slow', function(){ $trash.remove(); }); //chrome + confirm bug made slideUp not working...
			$trash.animate({
					opacity: 0.25,
					height: 0,
				}, 500, function() {
					$(this).remove();
			});
			return false; //Prevent the browser jump to the link anchor
		} else {
		return false;
		}	
	});
	
	//Add new slide
	$(".slide_add_button").live('click', function(){		
		var slidesContainer = $(this).prev();
		var sliderId = slidesContainer.attr('id');
		var sliderInt = $('#'+sliderId).attr('rel');
		
		var numArr = $('#'+sliderId +' li').find('.order').map(function() { 
			var str = this.id; 
			str = str.replace(/\D/g,'');
			str = parseFloat(str);
			return str;			
		}).get();
		
		var maxNum = Math.max.apply(Math, numArr);
		if (maxNum < 1 ) { maxNum = 0};
		var newNum = maxNum + 1;
		
		var newSlide = '<li class="temphide"><div class="slide_header"><strong>Slide ' + newNum + '</strong><input type="hidden" class="slide of-input order" name="' + sliderId + '[' + newNum + '][order]" id="' + sliderId + '_slide_order-' + newNum + '" value="' + newNum + '"><a class="slide_edit_button" href="#">Edit</a></div><div class="slide_body" style="display: none; "><label>Title</label><input class="slide of-input of-slider-title" name="' + sliderId + '[' + newNum + '][title]" id="' + sliderId + '_' + newNum + '_slide_title" value=""><label>Image URL</label><input class="slide of-input" name="' + sliderId + '[' + newNum + '][url]" id="' + sliderId + '_' + newNum + '_slide_url" value=""><div class="upload_button_div"><span class="button media_upload_button" id="' + sliderId + '_' + newNum + '" rel="'+sliderInt+'">Upload</span><span class="button mlu_remove_button hide" id="reset_' + sliderId + '_' + newNum + '" title="' + sliderId + '_' + newNum + '">Remove</span></div><div class="screenshot"></div><label>Link URL (optional)</label><input class="slide of-input" name="' + sliderId + '[' + newNum + '][link]" id="' + sliderId + '_' + newNum + '_slide_link" value=""><label>Description (optional)</label><textarea class="slide of-input" name="' + sliderId + '[' + newNum + '][description]" id="' + sliderId + '_' + newNum + '_slide_description" cols="8" rows="8"></textarea><a class="slide_delete_button" href="#">Delete</a><div class="clear"></div></div></li>';
		
		slidesContainer.append(newSlide);
		$('.temphide').fadeIn('fast', function() {
			$(this).removeClass('temphide');
		});
				
		of_image_upload(); // re-initialise upload image..
		
		return false; //prevent jumps, as always..
	});	
	
	//Sort slides
	jQuery('.slider').find('ul').each( function() {
		var id = jQuery(this).attr('id');
		$('#'+ id).sortable({
			placeholder: "placeholder",
			opacity: 0.6
		});	
	});
	
	
	/**	Sorter (Layout Manager) */
	jQuery('.sorter').each( function() {
		var id = jQuery(this).attr('id');
		$('#'+ id).find('ul').sortable({
			items: 'li',
			placeholder: "placeholder",
			connectWith: '.sortlist_' + id,
			opacity: 0.6,
			update: function() {
				$(this).find('.position').each( function() {
				
					var listID = $(this).parent().attr('id');
					var parentID = $(this).parent().parent().attr('id');
					parentID = parentID.replace(id + '_', '')
					var optionID = $(this).parent().parent().parent().attr('id');
					$(this).prop("name", optionID + '[' + parentID + '][' + listID + ']');
					
				});
			}
		});	
	});
	
	
	/**	Ajax Backup & Restore MOD */
	//backup button
	$('#of_backup_button').live('click', function(){
	
		var answer = confirm("Click OK to backup your current saved options.")
		
		if (answer){
	
			var clickedObject = $(this);
			var clickedID = $(this).attr('id');
					
			var nonce = $('#security').val();
		
			var data = {
				action: 'of_ajax_post_action',
				type: 'backup_options',
				security: nonce
			};
						
			$.post(ajaxurl, data, function(response) {
							
				//check nonce
				if(response==-1){ //failed
								
					var fail_popup = $('#of-popup-fail');
					fail_popup.fadeIn();
					window.setTimeout(function(){
						fail_popup.fadeOut();                        
					}, 2000);
				}
							
				else {
							
					var success_popup = $('#of-popup-save');
					success_popup.fadeIn();
					window.setTimeout(function(){
						location.reload();                        
					}, 1000);
				}
							
			});
			
		}
		
	return false;
					
	}); 
	
	//restore button
	$('#of_restore_button').live('click', function(){
	
		var answer = confirm("'Warning: All of your current options will be replaced with the data from your last backup! Proceed?")
		
		if (answer){
	
			var clickedObject = $(this);
			var clickedID = $(this).attr('id');
					
			var nonce = $('#security').val();
		
			var data = {
				action: 'of_ajax_post_action',
				type: 'restore_options',
				security: nonce
			};
						
			$.post(ajaxurl, data, function(response) {
			
				//check nonce
				if(response==-1){ //failed
								
					var fail_popup = $('#of-popup-fail');
					fail_popup.fadeIn();
					window.setTimeout(function(){
						fail_popup.fadeOut();                        
					}, 2000);
				}
							
				else {
							
					var success_popup = $('#of-popup-save');
					success_popup.fadeIn();
					window.setTimeout(function(){
						location.reload();                        
					}, 1000);
				}	
						
			});
	
		}
	
	return false;
					
	});
	
	/**	Ajax Transfer (Import/Export) Option */
	$('#of_import_button').live('click', function(){
	
		var answer = confirm("Click OK to import options.")
		
		if (answer){
	
			var clickedObject = $(this);
			var clickedID = $(this).attr('id');
					
			var nonce = $('#security').val();
			
			var import_data = $('#export_data').val();
		
			var data = {
				action: 'of_ajax_post_action',
				type: 'import_options',
				security: nonce,
				data: import_data
			};
						
			$.post(ajaxurl, data, function(response) {
				var fail_popup = $('#of-popup-fail');
				var success_popup = $('#of-popup-save');
				
				//check nonce
				if(response==-1){ //failed
					fail_popup.fadeIn();
					window.setTimeout(function(){
						fail_popup.fadeOut();                        
					}, 2000);
				}		
				else 
				{
					success_popup.fadeIn();
					window.setTimeout(function(){
						location.reload();                        
					}, 1000);
				}
							
			});
			
		}
		
	return false;
					
	});
	
	/** AJAX Save Options */
	$('#of_save').live('click',function() {
			
		var nonce = $('#security').val();
					
		$('.ajax-loading-img').fadeIn();
		
		//get serialized data from all our option fields			
		var serializedReturn = $('#of_form :input[name][name!="security"][name!="of_reset"]').serialize();
						
		var data = {
			type: 'save',
			action: 'of_ajax_post_action',
			security: nonce,
			data: serializedReturn
		};
					
		$.post(ajaxurl, data, function(response) {
			var success = $('#of-popup-save');
			var fail = $('#of-popup-fail');
			var loading = $('.ajax-loading-img');
			loading.fadeOut();  
						
			if (response==1) {
				success.fadeIn();
			} else { 
				fail.fadeIn();
			}
						
			window.setTimeout(function(){
				success.fadeOut(); 
				fail.fadeOut();				
			}, 2000);
		});
			
	return false; 
					
	});   
	
	
	/* AJAX Options Reset */	
	$('#of_reset').click(function() {
		
		//confirm reset
		var answer = confirm("Click OK to reset. All settings will be lost and replaced with default settings!");
		
		//ajax reset
		if (answer){
			
			var nonce = $('#security').val();
						
			$('.ajax-reset-loading-img').fadeIn();
							
			var data = {
			
				type: 'reset',
				action: 'of_ajax_post_action',
				security: nonce,
			};
						
			$.post(ajaxurl, data, function(response) {
				var success = $('#of-popup-reset');
				var fail = $('#of-popup-fail');
				var loading = $('.ajax-reset-loading-img');
				loading.fadeOut();  
							
				if (response==1)
				{
					success.fadeIn();
					window.setTimeout(function(){
						location.reload();                        
					}, 1000);
				} 
				else 
				{ 
					fail.fadeIn();
					window.setTimeout(function(){
						fail.fadeOut();				
					}, 2000);
				}
							

			});
			
		}
			
	return false;
		
	});


	/**	Tipsy @since v1.3 */
	if (jQuery().tipsy) {
		$('.typography-size, .typography-height, .typography-face, .typography-style, .of-typography-color').tipsy({
			fade: true,
			gravity: 's',
			opacity: 0.7,
		});
	}
	
	
	/**
	  * JQuery UI Slider function
	  * Dependencies 	 : jquery, jquery-ui-slider
	  * Feature added by : Smartik - http://smartik.ws/
	  * Date 			 : 03.17.2013
	  */
	jQuery('.smof_sliderui').each(function() {
		
		var obj   = jQuery(this);
		var sId   = "#" + obj.data('id');
		var val   = parseInt(obj.data('val'));
		var min   = parseInt(obj.data('min'));
		var max   = parseInt(obj.data('max'));
		var step  = parseInt(obj.data('step'));
		
		//slider init
		obj.slider({
			value: val,
			min: min,
			max: max,
			step: step,
			slide: function( event, ui ) {
				jQuery(sId).val( ui.value );
			}
		});
		
	});
	
	
	/**
	  * Switch
	  * Dependencies 	 : jquery
	  * Feature added by : Smartik - http://smartik.ws/
	  * Date 			 : 03.17.2013
	  */
	jQuery(".cb-enable").click(function(){
		var parent = $(this).parents('.switch-options');
		jQuery('.cb-disable',parent).removeClass('selected');
		jQuery(this).addClass('selected');
		jQuery('.main_checkbox',parent).attr('checked', true);
		
		//fold/unfold related options
		var obj = jQuery(this);
		var $fold='.f_'+obj.data('id');
		jQuery($fold).slideDown('normal', "swing");
	});
	jQuery(".cb-disable").click(function(){
		var parent = $(this).parents('.switch-options');
		jQuery('.cb-enable',parent).removeClass('selected');
		jQuery(this).addClass('selected');
		jQuery('.main_checkbox',parent).attr('checked', false);
		
		//fold/unfold related options
		var obj = jQuery(this);
		var $fold='.f_'+obj.data('id');
		jQuery($fold).slideUp('normal', "swing");
	});
	//disable text select(for modern chrome, safari and firefox is done via CSS)
	if (($.browser.msie && $.browser.version < 10) || $.browser.opera) { 
		$('.cb-enable span, .cb-disable span').find().attr('unselectable', 'on');
	}
	
	
	/**
	  * Google Fonts
	  * Dependencies 	 : google.com, jquery
	  * Feature added by : Smartik - http://smartik.ws/
	  * Date 			 : 03.17.2013
	  */
	function GoogleFontSelect( slctr, mainID ){
		
		var _selected = $(slctr).val(); 						//get current value - selected and saved
		var _linkclass = 'style_link_'+ mainID;
		var _previewer = mainID +'_ggf_previewer';
		
		if( _selected ){ //if var exists and isset
			
			//Check if selected is not equal with "Select a font" and execute the script.
			if ( _selected !== 'none' && _selected !== 'Select a font' ) {
				
				//remove other elements crested in <head>
				$( '.'+ _linkclass ).remove();
				
				//replace spaces with "+" sign
				var the_font = _selected.replace(/\s+/g, '+');
				
				//add reference to google font family
				$('head').append('<link href="http://fonts.googleapis.com/css?family='+ the_font +'" rel="stylesheet" type="text/css" class="'+ _linkclass +'">');
				
				//show in the preview box the font
				$('.'+ _previewer ).css('font-family', _selected +', sans-serif' );
				
			}else{
				
				//if selected is not a font remove style "font-family" at preview box
				$('.'+ _previewer ).css('font-family', '' );
				
			}
		
		}
	
	}
	
	//init for each element
	jQuery( '.google_font_select' ).each(function(){ 
		var mainID = jQuery(this).attr('id');
		GoogleFontSelect( this, mainID );
	});
	
	//init when value is changed
	jQuery( '.google_font_select' ).change(function(){ 
		var mainID = jQuery(this).attr('id');
		GoogleFontSelect( this, mainID );
	});
	
	

}); //end doc ready

jQuery(document).ready(function($) {
	var colors = {
		color_0: {
			body_bg: '#eee',
			header_bg: '#fff',
			header_text: '#666',
			header_text_hover: '#d13a7a',
			search_bg: '#d13a7a',
			search_text: '#fff',
			header_ext_bg: '#f5f5f5',
			header_ext_text: '#999',
			header_ext_text_hover: '#d13a7a',
			menu_hover_bg: '#fff',
			menu_hover_text: '#d13a7a',			
			menu_active_bg: '#fff',
			menu_active_text: '#d13a7a',
			drop_bg: '#fff',
			drop_text: '#666',
			drop_hover_bg: '#d13a7a',
			drop_hover_text: '#fff',			
			drop_active_bg: '#fff',
			drop_active_text: '#d13a7a',
			main_bg: '#fff',
			main_bg_alternative: '#f2f2f2',
			main_border: '#e8e8e8',
			main_heading: '#444',
			main_text: '#666',
			main_primary: '#d13a7a',
			main_secondary: '#666',
			main_fade: '#999',
			alt_bg: '#f2f2f2',
			alt_bg_alternative: '#fff',
			alt_border: '#ddd',
			alt_heading: '#333',
			alt_text: '#555',
			alt_primary: '#d13a7a',
			alt_secondary: '#666',
			alt_fade: '#999',
			subfooter_bg: '#1a1a1a',
			subfooter_border: '#222',
			subfooter_text: '#808080',
			subfooter_heading: '#ccc',
			subfooter_link: '#ccc',
			subfooter_link_hover: '#fff',
			subfooter_fade: '#666',
			footer_bg: '#222',
			footer_text: '#666',
			footer_link: '#999',
			footer_link_hover: '#fff'
		},
		color_1: {
			body_bg: '#222',
			header_bg: '#444',
			header_text: '#ccc',
			header_text_hover: '#1abc9c',
			search_bg: '#1abc9c',
			search_text: '#fff',
			header_ext_bg: '#393939',
			header_ext_text: '#ccc',
			header_ext_text_hover: '#1abc9c',
			menu_hover_bg: '#444',
			menu_hover_text: '#1abc9c',			
			menu_active_bg: '#444',
			menu_active_text: '#1abc9c',
			drop_bg: '#444',
			drop_text: '#ccc',
			drop_hover_bg: '#1abc9c',
			drop_hover_text: '#fff',			
			drop_active_bg: '#444',
			drop_active_text: '#1abc9c',
			main_bg: '#444',
			main_bg_alternative: '#393939',
			main_border: '#595959',
			main_heading: '#fff',
			main_text: '#ccc',
			main_primary: '#1abc9c',
			main_secondary: '#fab908',
			main_fade: '#888',
			alt_bg: '#393939',
			alt_bg_alternative: '#444',
			alt_border: '#444',
			alt_heading: '#fff',
			alt_text: '#ccc',
			alt_primary: '#1abc9c',
			alt_secondary: '#fab908',
			alt_fade: '#888',
			subfooter_bg: '#303030',
			subfooter_border: '#444',
			subfooter_text: '#808080',
			subfooter_heading: '#ccc',
			subfooter_link: '#ccc',
			subfooter_link_hover: '#fab908',
			subfooter_fade: '#666',
			footer_bg: '#222',
			footer_text: '#666',
			footer_link: '#aaa',
			footer_link_hover: '#fab908'
		},
		color_2: {
			body_bg: '#342845',
			header_bg: '#523f6d',
			header_text: '#fff',
			header_text_hover: '#a3b745',
			search_bg: '#523f6d',
			search_text: '#fff',
			header_ext_bg: '#413256',
			header_ext_text: '#bfb9c8',
			header_ext_text_hover: '#a3b745',
			menu_hover_bg: '#523f6d',
			menu_hover_text: '#a3b745',			
			menu_active_bg: '#523f6d',
			menu_active_text: '#a3b745',
			drop_bg: '#523f6d',
			drop_text: '#fff',
			drop_hover_bg: '#a3b745',
			drop_hover_text: '#fff',			
			drop_active_bg: '#523f6d',
			drop_active_text: '#a3b745',
			main_bg: '#f1f0f2',
			main_bg_alternative: '#fff',
			main_border: '#e2e1e5',
			main_heading: '#403949',
			main_text: '#403949',
			main_primary: '#a3b745',
			main_secondary: '#d46f15',
			main_fade: '#979699',
			alt_bg: '#e2e1e5',
			alt_bg_alternative: '#fff',
			alt_border: '#d3d2d6',
			alt_heading: '#403949',
			alt_text: '#403949',
			alt_primary: '#a3b745',
			alt_secondary: '#d46f15',
			alt_fade: '#979699',
			subfooter_bg: '#523f6d',
			subfooter_border: '#63517d',
			subfooter_text: '#a598b7',
			subfooter_heading: '#dedae3',
			subfooter_link: '#dedae3',
			subfooter_link_hover: '#fff',
			subfooter_fade: '#a598b7',
			footer_bg: '#413256',
			footer_text: '#a598b7',
			footer_link: '#dedae3',
			footer_link_hover: '#fff'
		},
		color_3: {
			body_bg: '#e3e6e8',
			header_bg: '#363b3f',
			header_text: '#fff',
			header_text_hover: '#e14d43',
			search_bg: '#e14d43',
			search_text: '#fff',
			header_ext_bg: '#25282b',
			header_ext_text: '#c2c4c5',
			header_ext_text_hover: '#e14d43',
			menu_hover_bg: '#363b3f',
			menu_hover_text: '#e14d43',			
			menu_active_bg: '#363b3f',
			menu_active_text: '#e14d43',
			drop_bg: '#363b3f',
			drop_text: '#fff',
			drop_hover_bg: '#e14d43',
			drop_hover_text: '#fff',			
			drop_active_bg: '#363b3f',
			drop_active_text: '#e14d43',
			main_bg: '#fff',
			main_bg_alternative: '#edf0f2',
			main_border: '#e1e5e8',
			main_heading: '#25282',
			main_text: '#363b3f',
			main_primary: '#e14d43',
			main_secondary: '#69a8bb',
			main_fade: '#999c9f',
			alt_bg: '#edf0f2',
			alt_bg_alternative: '#fff',
			alt_border: '#d7dde0',
			alt_heading: '#25282b',
			alt_text: '#363b3f',
			alt_primary: '#e14d43',
			alt_secondary: '#69a8bb',
			alt_fade: '#999c9f',
			subfooter_bg: '#363b3f',
			subfooter_border: '#494e52',
			subfooter_text: '#999c9f',
			subfooter_heading: '#c2c4c5',
			subfooter_link: '#c2c4c5',
			subfooter_link_hover: '#69a8bb',
			subfooter_fade: '#7a7f83',
			footer_bg: '#25282b',
			footer_text: '#7a7f83',
			footer_link: '#c2c4c5',
			footer_link_hover: '#69a8bb'
		},
		color_4: {
			body_bg: '#ddd',
			header_bg: '#1a1a1a',
			header_text: '#ddd',
			header_text_hover: '#32beeb',
			search_bg: '#32beeb',
			search_text: '#fff',
			header_ext_bg: '#222',
			header_ext_text: '#999',
			header_ext_text_hover: '#32beeb',
			menu_hover_bg: '#32beeb',
			menu_hover_text: '#fff',			
			menu_active_bg: '#1a1a1a',
			menu_active_text: '#32beeb',
			drop_bg: '#32beeb',
			drop_text: '#fff',
			drop_hover_bg: '#1a1a1a',
			drop_hover_text: '#fff',			
			drop_active_bg: '#28aad4',
			drop_active_text: '#fff',
			main_bg: '#fff',
			main_bg_alternative: '#edf1f2',
			main_border: '#e1e5e8',
			main_heading: '#222',
			main_text: '#444',
			main_primary: '#32beeb',
			main_secondary: '#666',
			main_fade: '#999c9f',
			alt_bg: '#edf1f2',
			alt_bg_alternative: '#fff',
			alt_border: '#d7dde0',
			alt_heading: '#222',
			alt_text: '#444',
			alt_primary: '#32beeb',
			alt_secondary: '#666',
			alt_fade: '#999c9f',
			subfooter_bg: '#1a1a1a',
			subfooter_border: '#222',
			subfooter_text: '#777',
			subfooter_heading: '#ccc',
			subfooter_link: '#ccc',
			subfooter_link_hover: '#32beeb',
			subfooter_fade: '#666',
			footer_bg: '#222',
			footer_text: '#666',
			footer_link: '#bbb',
			footer_link_hover: '#32beeb'
		},
		color_5: {
			body_bg: '#87a8a5',
			header_bg: '#738e96',
			header_text: '#fff',
			header_text_hover: '#b2dab5',
			search_bg: '#b2dab5',
			search_text: '#38505c',
			header_ext_bg: '#627c83',
			header_ext_text: '#d5dddf',
			header_ext_text_hover: '#fff',
			menu_hover_bg: '#738e96',
			menu_hover_text: '#b2dab5',			
			menu_active_bg: '#738e96',
			menu_active_text: '#b2dab5',
			drop_bg: '#738e96',
			drop_text: '#fff',
			drop_hover_bg: '#627c83',
			drop_hover_text: '#fff',			
			drop_active_bg: '#627c83',
			drop_active_text: '#b2dab5',
			main_bg: '#fff',
			main_bg_alternative: '#edf1f2',
			main_border: '#e1e5e8',
			main_heading: '#38505c',
			main_text: '#505c5f',
			main_primary: '#9ebaa0',
			main_secondary: '#aa9d88',
			main_fade: '#999c9f',
			alt_bg: '#edf1f2',
			alt_bg_alternative: '#fff',
			alt_border: '#d7dde0',
			alt_heading: '#38505c',
			alt_text: '#505c5f',
			alt_primary: '#9ebaa0',
			alt_secondary: '#aa9d88',
			alt_fade: '#999c9f',
			subfooter_bg: '#738e96',
			subfooter_border: '#839da4',
			subfooter_text: '#d5dddf',
			subfooter_heading: '#fff',
			subfooter_link: '#fff',
			subfooter_link_hover: '#fff',
			subfooter_fade: '#bbc5c7',
			footer_bg: '#627c83',
			footer_text: '#bbc5c7',
			footer_link: '#d5dddf',
			footer_link_hover: '#fff'
		},
		color_6: {
			body_bg: '#59524c',
			header_bg: '#59524c',
			header_text: '#fff',
			header_text_hover: '#c7a589',
			search_bg: '#c7a589',
			search_text: '#fff',
			header_ext_bg: '#46403c',
			header_ext_text: '#cdcbc9',
			header_ext_text_hover: '#c7a589',
			menu_hover_bg: '#46403c',
			menu_hover_text: '#fff',			
			menu_active_bg: '#59524c',
			menu_active_text: '#c7a589',
			drop_bg: '#46403c',
			drop_text: '#fff',
			drop_hover_bg: '#e5e3e1',
			drop_hover_text: '#46403c',			
			drop_active_bg: '#46403c',
			drop_active_text: '#c7a589',
			main_bg: '#f2f1f0',
			main_bg_alternative: '#fff',
			main_border: '#e0dedc',
			main_heading: '#46403c',
			main_text: '#46403c',
			main_primary: '#c7a589',
			main_secondary: '#9ea476',
			main_fade: '#979699',
			alt_bg: '#e5e3e1',
			alt_bg_alternative: '#f2f1f0',
			alt_border: '#d6d4d2',
			alt_heading: '#46403c',
			alt_text: '#46403c',
			alt_primary: '#c7a589',
			alt_secondary: '#9ea476',
			alt_fade: '#979699',
			subfooter_bg: '#59524c',
			subfooter_border: '#69625c',
			subfooter_text: '#b1a9a2',
			subfooter_heading: '#ddd6d0',
			subfooter_link: '#ddd6d0',
			subfooter_link_hover: '#fff',
			subfooter_fade: '#98918a',
			footer_bg: '#46403c',
			footer_text: '#98918a',
			footer_link: '#b1a9a2',
			footer_link_hover: '#fff'
		},
		color_7: {
			body_bg: '#333',
			header_bg: '#cf4944',
			header_text: '#fff',
			header_text_hover: '#ebbc00',
			search_bg: '#b43c38',
			search_text: '#fff',
			header_ext_bg: '#333',
			header_ext_text: '#ccc',
			header_ext_text_hover: '#fff',
			menu_hover_bg: '#b43c38',
			menu_hover_text: '#fff',			
			menu_active_bg: '#ebbc00',
			menu_active_text: '#fff',
			drop_bg: '#b43c38',
			drop_text: '#fff',
			drop_hover_bg: '#ebbc00',
			drop_hover_text: '#fff',			
			drop_active_bg: '#b43c38',
			drop_active_text: '#ebbc00',
			main_bg: '#fff',
			main_bg_alternative: '#f2efed',
			main_border: '#e8e4e1',
			main_heading: '#453d3d',
			main_text: '#444',
			main_primary: '#e87821',
			main_secondary: '#ebbc00',
			main_fade: '#9e9a98',
			alt_bg: '#f2efed',
			alt_bg_alternative: '#fff',
			alt_border: '#e0dbd7',
			alt_heading: '#453d3d',
			alt_text: '#444',
			alt_primary: '#e87821',
			alt_secondary: '#ebbc00',
			alt_fade: '#9e9a98',
			subfooter_bg: '#cf4944',
			subfooter_border: '#d65d59',
			subfooter_text: '#ecc5c3',
			subfooter_heading: '#fff',
			subfooter_link: '#fff',
			subfooter_link_hover: '#fff',
			subfooter_fade: '#e6b4b2',
			footer_bg: '#333',
			footer_text: '#777',
			footer_link: '#bbb',
			footer_link_hover: '#ebbc00'
		},
		color_8: {
			body_bg: '#38424a',
			header_bg: '#21282e',
			header_text: '#b0b6be',
			header_text_hover: '#71a7d3',
			search_bg: '#71a7d3',
			search_text: '#fff',
			header_ext_bg: '#1c2126',
			header_ext_text: '#b0b6be',
			header_ext_text_hover: '#71a7d3',
			menu_hover_bg: '#1c2126',
			menu_hover_text: '#b0b6be',			
			menu_active_bg: '#21282e',
			menu_active_text: '#71a7d3',
			drop_bg: '#1c2126',
			drop_text: '#b0b6be',
			drop_hover_bg: '#71a7d3',
			drop_hover_text: '#fff',			
			drop_active_bg: '#1c2126',
			drop_active_text: '#71a7d3',
			main_bg: '#21282e',
			main_bg_alternative: '#1c2126',
			main_border: '#303940',
			main_heading: '#d0d5db',
			main_text: '#bfc4c9',
			main_primary: '#71a7d3',
			main_secondary: '#47b38f',
			main_fade: '#757b83',
			alt_bg: '#1c2126',
			alt_bg_alternative: '#21282e',
			alt_border: '#303940',
			alt_heading: '#d0d5db',
			alt_text: '#bfc4c9',
			alt_primary: '#71a7d3',
			alt_secondary: '#47b38f',
			alt_fade: '#757b83',
			subfooter_bg: '#1c2126',
			subfooter_border: '#21282e',
			subfooter_text: '#939aa2',
			subfooter_heading: '#ccd0d4',
			subfooter_link: '#ccd0d4',
			subfooter_link_hover: '#47b38f',
			subfooter_fade: '#787d81',
			footer_bg: '#21282e',
			footer_text: '#939aa2',
			footer_link: '#ccd0d4',
			footer_link_hover: '#47b38f'
		},
		color_9: {
			body_bg: '#eee',
			header_bg: '#fff',
			header_text: '#666',
			header_text_hover: '#1b98e0',
			search_bg: '#fff',
			search_text: '#1b98e0',
			header_ext_bg: '#f5f5f5',
			header_ext_text: '#777',
			header_ext_text_hover: '#1b98e0',
			menu_hover_bg: '#1b98e0',
			menu_hover_text: '#fff',			
			menu_active_bg: '#fff',
			menu_active_text: '#1b98e0',
			drop_bg: '#1b98e0',
			drop_text: '#fff',
			drop_hover_bg: '#fff',
			drop_hover_text: '#1b98e0',			
			drop_active_bg: '#1487ca',
			drop_active_text: '#fff',
			main_bg: '#fff',
			main_bg_alternative: '#f2f2f2',
			main_border: '#e8e8e8',
			main_heading: '#555',
			main_text: '#666',
			main_primary: '#1b98e0',
			main_secondary: '#447490',
			main_fade: '#999',
			alt_bg: '#f2f2f2',
			alt_bg_alternative: '#fff',
			alt_border: '#ddd',
			alt_heading: '#444',
			alt_text: '#666',
			alt_primary: '#1b98e0',
			alt_secondary: '#447490',
			alt_fade: '#999',
			subfooter_bg: '#333',
			subfooter_border: '#444',
			subfooter_text: '#aaa',
			subfooter_heading: '#ddd',
			subfooter_link: '#ddd',
			subfooter_link_hover: '#1b98e0',
			subfooter_fade: '#777',
			footer_bg: '#fff',
			footer_text: '#999',
			footer_link: '#666',
			footer_link_hover: '#1b98e0'
		}
	}

	function update_custom_colors(color_scheme){
		for (var field_id in color_scheme) {
			var color_hex = color_scheme[field_id];
			jQuery('#section-' + field_id + ' .colorSelector').ColorPickerSetColor(color_hex);
			jQuery('#section-' + field_id + ' .colorSelector').children('div').css('backgroundColor', color_hex);
			jQuery('#section-' + field_id + ' .of-color').val(color_hex);

		}
	}

	jQuery('#color_scheme').change(function() {
		switch ($(this).val()){
			case 'White Pink': update_custom_colors(colors.color_0); break;
			case 'Grey Turquoise': update_custom_colors(colors.color_1); break;
			case 'Ectoplasm': update_custom_colors(colors.color_2); break;
			case 'Midnight Red': update_custom_colors(colors.color_3); break;
			case 'Stylish Cyan': update_custom_colors(colors.color_4); break;
			case 'Light Ocean': update_custom_colors(colors.color_5); break;
			case 'Coffee Shop': update_custom_colors(colors.color_6); break;
			case 'Bright Sunrise': update_custom_colors(colors.color_7); break;
			case 'Twilight': update_custom_colors(colors.color_8); break;
			case 'White Blue': update_custom_colors(colors.color_9); break;
		}

	});

    jQuery('#main_header_layout').live('change', function(){
        if (jQuery(this).val() == 'STANDARD + TOP (contacts, socials, lang)' || jQuery(this).val() == 'ADVANCED (menu below logo)') {

            jQuery('#section-header_phone').fadeIn();
            jQuery('#section-header_email').fadeIn();
            jQuery('#section-header_social_facebook').fadeIn();
            jQuery('#section-header_social_twitter').fadeIn();
            jQuery('#section-header_social_google').fadeIn();
            jQuery('#section-header_social_linkedin').fadeIn();
            jQuery('#section-header_social_youtube').fadeIn();
            jQuery('#section-header_social_vimeo').fadeIn();
            jQuery('#section-header_social_flickr').fadeIn();
            jQuery('#section-header_social_instagram').fadeIn();
            jQuery('#section-header_social_xing').fadeIn();
            jQuery('#section-header_social_pinterest').fadeIn();
            jQuery('#section-header_social_skype').fadeIn();
            jQuery('#section-header_social_tumblr').fadeIn();
            jQuery('#section-header_social_dribbble').fadeIn();
            jQuery('#section-header_social_vk').fadeIn();

			jQuery('#section-header_show_language').fadeIn();
			jQuery('#section-header_show_language .controls').click();
		} else {
			jQuery('#section-header_show_language').fadeOut();
			jQuery('#section-header_language_type').fadeOut();
			jQuery('#section-header_language_amount').fadeOut();
			jQuery('#section-header_language_1_name').fadeOut();
			jQuery('#section-header_language_2_name').fadeOut();
			jQuery('#section-header_language_2_url').fadeOut();
			jQuery('#section-header_language_3_name').fadeOut();
			jQuery('#section-header_language_3_url').fadeOut();
			jQuery('#section-header_language_4_name').fadeOut();
			jQuery('#section-header_language_4_url').fadeOut();
			jQuery('#section-header_language_5_name').fadeOut();
			jQuery('#section-header_language_5_url').fadeOut();
			jQuery('#section-header_language_6_name').fadeOut();
			jQuery('#section-header_language_6_url').fadeOut();
			jQuery('#section-header_language_7_name').fadeOut();
			jQuery('#section-header_language_7_url').fadeOut();
			jQuery('#section-header_language_8_name').fadeOut();
			jQuery('#section-header_language_8_url').fadeOut();
			jQuery('#section-header_language_9_name').fadeOut();
			jQuery('#section-header_language_9_url').fadeOut();
			jQuery('#section-header_language_10_name').fadeOut();
			jQuery('#section-header_language_10_url').fadeOut();

            jQuery('#section-header_phone').fadeOut();
            jQuery('#section-header_email').fadeOut();
            jQuery('#section-header_social_facebook').fadeOut();
            jQuery('#section-header_social_twitter').fadeOut();
            jQuery('#section-header_social_google').fadeOut();
            jQuery('#section-header_social_linkedin').fadeOut();
            jQuery('#section-header_social_youtube').fadeOut();
            jQuery('#section-header_social_vimeo').fadeOut();
            jQuery('#section-header_social_flickr').fadeOut();
            jQuery('#section-header_social_instagram').fadeOut();
            jQuery('#section-header_social_xing').fadeOut();
            jQuery('#section-header_social_pinterest').fadeOut();
            jQuery('#section-header_social_skype').fadeOut();
            jQuery('#section-header_social_tumblr').fadeOut();
            jQuery('#section-header_social_dribbble').fadeOut();
            jQuery('#section-header_social_vk').fadeOut();
		}
	});

	jQuery('#section-header_show_language .controls').live('click', function(){
		if (jQuery('#section-header_show_language .controls .cb-enable').hasClass('selected')) {
			jQuery('#section-header_language_type').fadeIn();
			jQuery('#header_language_type').change();
		} else {
			jQuery('#section-header_language_type').fadeOut();
			jQuery('#section-header_language_amount').fadeOut();
			jQuery('#section-header_language_1_name').fadeOut();
			jQuery('#section-header_language_2_name').fadeOut();
			jQuery('#section-header_language_2_url').fadeOut();
			jQuery('#section-header_language_3_name').fadeOut();
			jQuery('#section-header_language_3_url').fadeOut();
			jQuery('#section-header_language_4_name').fadeOut();
			jQuery('#section-header_language_4_url').fadeOut();
			jQuery('#section-header_language_5_name').fadeOut();
			jQuery('#section-header_language_5_url').fadeOut();
			jQuery('#section-header_language_6_name').fadeOut();
			jQuery('#section-header_language_6_url').fadeOut();
			jQuery('#section-header_language_7_name').fadeOut();
			jQuery('#section-header_language_7_url').fadeOut();
			jQuery('#section-header_language_8_name').fadeOut();
			jQuery('#section-header_language_8_url').fadeOut();
			jQuery('#section-header_language_9_name').fadeOut();
			jQuery('#section-header_language_9_url').fadeOut();
			jQuery('#section-header_language_10_name').fadeOut();
			jQuery('#section-header_language_10_url').fadeOut();
		}
	});


	jQuery('#header_language_type').live('change', function(){
		if (jQuery(this).val() == 'Your own links') {
			jQuery('#section-header_language_amount').fadeIn();
			jQuery('#section-header_language_1_name').fadeIn();
			jQuery('#header_language_amount').change();
		} else {
			jQuery('#section-header_language_amount').fadeOut();
			jQuery('#section-header_language_1_name').fadeOut();
			jQuery('#section-header_language_2_name').fadeOut();
			jQuery('#section-header_language_2_url').fadeOut();
			jQuery('#section-header_language_3_name').fadeOut();
			jQuery('#section-header_language_3_url').fadeOut();
			jQuery('#section-header_language_4_name').fadeOut();
			jQuery('#section-header_language_4_url').fadeOut();
			jQuery('#section-header_language_5_name').fadeOut();
			jQuery('#section-header_language_5_url').fadeOut();
			jQuery('#section-header_language_6_name').fadeOut();
			jQuery('#section-header_language_6_url').fadeOut();
			jQuery('#section-header_language_7_name').fadeOut();
			jQuery('#section-header_language_7_url').fadeOut();
			jQuery('#section-header_language_8_name').fadeOut();
			jQuery('#section-header_language_8_url').fadeOut();
			jQuery('#section-header_language_9_name').fadeOut();
			jQuery('#section-header_language_9_url').fadeOut();
			jQuery('#section-header_language_10_name').fadeOut();
			jQuery('#section-header_language_10_url').fadeOut();
		}
	});

	jQuery('#header_language_amount').live('change', function(){
		for(var i = 2; i <= 10; i++) {
			if (i <= jQuery(this).val()-0) {
				jQuery('#section-header_language_'+i+'_name').fadeIn();
				jQuery('#section-header_language_'+i+'_url').fadeIn();
			} else {
				jQuery('#section-header_language_'+i+'_name').fadeOut();
				jQuery('#section-header_language_'+i+'_url').fadeOut();
			}
		}
	});

    jQuery('#main_header_layout').change();

    jQuery('.of-color').on('change', function(){
        jQuery(this).siblings('.colorSelector').ColorPickerSetColor(jQuery(this).val());
        jQuery(this).siblings('.colorSelector').children('div').css('backgroundColor', jQuery(this).val());
    })

});